package cn.hh.redis.util;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author huangh
 * @date 2021/11/26
 * @Description:
 */
public class OrderCertResult {
    //29BC0CB57D59A7872FE00F06   C9F95A0A5AF052BFFCE5C89917335B76
    private final static String key = "C9F95A0A5AF052BFFCE5C89917335B76";
    private final static String authCode = "certAbility";
    private final static String appCode = "FJWT";
    private final static String sysCode = "UOP101";//UOP101
/*
    {
        "head": {
            "sysCode": "S00101",
            "appCode": "FJDQGONGZH",
            "transactionId": "S00101A010131410152301988989769ac044a6a52885475707c30d",
            "reqTime": "2017-09-07 20:32:03",
            "method": "qryLivingResult",
            "version": 1,
            "attach": "hello,189.cn",
            "sign": "7e032eecc0172d3bc9395ec64d298bd6"
        },
        "biz": {
            "openNo": "test20211028201256"
        }
    }
*/
    public static String httpRequest(){
        String result = "";
        String url = "https://proc.fj.189.cn/uop-web/httpapi/service/execute";
        Map<String,Object> param = new LinkedHashMap<>();
        Map<String,Object> headParam = new LinkedHashMap<>();
        Map<String,Object> bizParam = new LinkedHashMap<>();
        param.put("head",headParam);
        param.put("biz",bizParam);

        //应用编码+时间(yymmddhhmm,10位)+GUID(32位)  yyyy-MM-dd HH:mm:ss
        String guid = IdUtil.randomUUID().replace("-","");
        //报文流水号  yyMMddHHmm
        String transactionId = sysCode + appCode + DateUtil.format(new Date(), "yyMMddHHmm")
                + guid;
        String reqTime = DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN);
        //消息签名，
        //格式：MD5 32位小写(报文流水号+生产系统分配的秘钥)
        String sign = UopMD5Utils.getInstance().encryptByMd5(transactionId + key).toLowerCase();

        headParam.put("sysCode",sysCode);
        headParam.put("appCode",appCode);
        headParam.put("transactionId",transactionId);
        headParam.put("reqTime",reqTime);
        headParam.put("method","qryLivingResult");
        headParam.put("version","1");
        headParam.put("attach","hello,189.cn");
        headParam.put("sign",sign);
        //FJ20211123213123123
        //FJ20211123213123125
        bizParam.put("openNo","FJ20211123213123123");

        System.out.println("入参：" + JSONUtil.toJsonStr(param));
        result = HttpUtil.post(url,JSONUtil.toJsonStr(param));
        System.out.println("出参：" + result);
        return result;
    }

    public static void main(String[] args) {
        /*String uuid = IdUtil.randomUUID();
        System.out.println(uuid);
        System.out.println(uuid.replace("-",""));
        System.out.println(uuid.replace("-","").length());


        String bizData = "{111111111}";
        String bizDateDec =  UopMD5Utils.getInstance().encryptByMd5(bizData + key).toLowerCase();
        System.out.println(bizDateDec);*/

        OrderCertResult.httpRequest();
    }







}
